package com.andova.camera.glsurface

import android.content.Context
import android.hardware.Camera
import android.opengl.GLSurfaceView
import android.util.AttributeSet
import com.andova.face.ICameraCheckListener
import com.andova.face.IFaceDetector
import com.andova.face.detector.IPreview
import javax.microedition.khronos.egl.EGLConfig
import javax.microedition.khronos.opengles.GL10

// todo extends TextureView
@Deprecated("", ReplaceWith("CameraGLSurfaceView"))
abstract class GLCameraSurfaceView(context: Context, attrs: AttributeSet?) : GLSurfaceView(context, attrs), GLSurfaceView.Renderer, IPreview {
    override fun setFaceDetector(faceDetector: IFaceDetector?): IPreview = previewer.setFaceDetector(faceDetector)
    override fun setCheckListener(checkListener: ICameraCheckListener?): IPreview = previewer.setCheckListener(checkListener)
    override fun setMinCameraPixels(minCameraPixels: Long): IPreview = previewer.setMinCameraPixels(minCameraPixels)
    override fun setDisplayOrientation(degree: Int): IPreview = previewer.setDisplayOrientation(degree)
    override fun toggleDrawPreview(draw: Boolean): IPreview {
        TODO("Not yet implemented")
    }

    override fun closeCamera() = previewer.closeCamera()
    override fun getCameraId(): Int = previewer.getCameraId()
    override fun setCameraId(cameraId: Int): IPreview = previewer.setCameraId(cameraId)
    override fun release() = previewer.release()
    override fun openCamera() = previewer.openCamera()
    override fun openCamera(callbackFrameData: Boolean) = previewer.openCamera()
    override fun openCamera(callbackFrameData: Boolean, frameRange: Int) = previewer.openCamera()

    fun bufferUpdated(): Boolean = previewer.bufferUpdated()
    fun bufferUpdated(value: Boolean) = previewer.bufferUpdated(value)
    fun getBufferY() = previewer.getBufferY()
    fun getBufferUV() = previewer.getBufferUV()
    fun getCameraHeight(): Int = previewer.getCameraHeight()
    fun getCameraWidth(): Int = previewer.getCameraWidth()
    fun getPreviewWidth(): Int = previewer.getPreviewWidth()
    fun getPreviewHeight(): Int = previewer.getPreviewHeight()
    fun getDisplayOrientation(): Int = previewer.getDisplayOrientation()
    fun getCamera(): Camera? = previewer.getCamera()
    private val previewer by lazy { ACameraBufferPreviewer(context, this, this) }

    constructor(context: Context) : this(context, null)

    final override fun onDrawFrame(gl: GL10?) = glDrawFrame(gl)
    final override fun onSurfaceCreated(gl: GL10?, config: EGLConfig?) = glSurfaceCreated(gl, config)
    final override fun onSurfaceChanged(gl: GL10?, width: Int, height: Int) = glSurfaceChanged(gl, width, height)
    protected abstract fun onRelease()
    protected abstract fun glDrawFrame(gl: GL10?)
    protected abstract fun glSurfaceCreated(gl: GL10?, config: EGLConfig?)
    protected abstract fun glSurfaceChanged(gl: GL10?, width: Int, height: Int)
}


